package com.winning.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestLock {

    public static void main(String[] args) {

        Ticket ticket = new Ticket();

        new Thread(ticket, "1号窗口").start();
        new Thread(ticket, "2号窗口").start();
        new Thread(ticket, "3号窗口").start();

    }

}

class Ticket implements Runnable{

    private int tick =1000;

    private Lock lock = new ReentrantLock();

    @Override
    public void run() {

        lock.lock();
        try{
            while (tick>0){
                System.out.println(Thread.currentThread().getName() + " 完成售票，余票为：" + --tick);
            }
        }finally {
            lock.unlock();
        }


    }
}
